<template>
  <div>
    <orderitem
      v-for="item in listData"
      :key="item.orderid"
      :dataSource="item.content.order"
      :title="item.orderid"
      :totalPrice="parseFloat(item.content.totalPrice)"
      :address="item.content.address"></orderitem>
  </div>
</template>
<script>
  import { findOrdersByUserId } from '@/api/book'
  import Orderitem from '@/components/mycomponents/OrderItem'

  export default {
    components: { Orderitem },
    data () {
      return {
        user: {},
        listData: []
      }
    },
    methods: {
      disablePay () {
        // console.log('*************** 触发 disablePay ***************')
        this.payable = true
      },
      // 模拟支付
      simpayment () {

      },
      loaddata () {
        // 重新加载购物车
        setTimeout(() => {
          findOrdersByUserId(this.user.id).then(res => {
            // console.log('**************收到返回值***************')
            // console.log(res)
            // console.log('**************findOrdersByUserId***************')
            // console.log(res.result)
            var tmplst = res.result
            tmplst.forEach((value, index, arr) => {
              // console.log(value)
              const tmp = value.content
              value.content = JSON.parse(tmp)
              // console.log(value)
            })
            this.listData = tmplst
            // console.log(this.listData)
          }).catch(error => {
            if (error.response && error.response.status === 403) {
              this.$message.error('api请求方式错误')
            }
            if (error.response && error.response.status === 404) {
              this.$message.error('api未找到')
            }
            if (error.response && error.response.status === 500) {
              this.$message.error('服务器内部错误')
            }
          })
        }, 100)
      }
    },
    computed: {
    },
    mounted () {

    },
    created () {
      this.loaddata()
      this.user = this.$store.getters.userInfo
    }
  }
</script>

<style scoped>
</style>
